package com.example.demospring.common.image;


import com.example.demospring.common.entity.Message;
import com.example.demospring.common.entity.MessageStatus;
import org.springframework.web.multipart.MultipartFile;

public interface ImageDao {
    void init() throws Exception;

    void destroy();

    Message upload(MultipartFile file);

    default Message upload(MultipartFile[] files){
        int count = 0, fileCount = 0;
        if(null != files && files.length>0){
            fileCount = files.length;
            for (MultipartFile file : files) {
                Message message = upload(file);
                if(message.getStatus()== MessageStatus.MS200){
                    count++;
                }
            }
        }
        return fileCount>0 && count==fileCount ? Message.succeed("图片上传成功") : Message.fail("图片上传失败");
    };

    Message delete(String md5);
}
